# -*- coding: utf-8 -*-
import pymysql
result = []
with open('./db_connection.txt','r',encoding='utf-8') as f:
    for line in f.readlines():
        line = line.rstrip("\n")
        list = line.split(",",6)
        IP = list[0]
        PORT = list[1]
        USER = list[2]
        DBNAME = list[3]
        PASSWORD = list[4]
        GAME_NAME = list[5]

        db = pymysql.connect(
                host=IP,
                port=int(PORT),
                user=USER,
                passwd=PASSWORD,
                db=DBNAME,
                charset="utf8"
        )
        cursor = db.cursor()
        # 创建\添加字段 语句
        # example:
        # ALTER TABLE game_site ADD `is_group`  INT(10) UNSIGNED DEFAULT '0' NULL COMMENT '是否有牌友群权限，0否，1是'  ;
        sql = """
                """

        try:
            cursor.execute(sql)
            db.commit()
            print(GAME_NAME , "successful implementation of SQL!")
        except:
            print(GAME_NAME , "already exists")
            db.rollback()

        # 提交到数据库执行(更新\新增\删除 需要执行commit)
        # db.commit()
db.close()
f.close()